package cn.school.test;

import cn.school.dao.StudentDao;
import cn.school.entity.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Mybatis1 {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        //findALL
        //1:
//        List<Student> list = session.selectList("cn.school.dao.StudentDao.findALL");
//        list.stream().forEach(System.out::println);

        //2:
        StudentDao mapper = session.getMapper(StudentDao.class);
        List<Student> list = mapper.findALL();
        list.stream().forEach(System.out::println);
        session.close();
    }
}
